<?php

namespace App\Admin\Extensions\Tools;

use Dcat\Admin\Grid\Tools\AbstractTool;
use Dcat\Admin\Widgets\Form;
use Dcat\Admin\Widgets\Modal;

class QuestionTools extends AbstractTool
{
    /**
     * 导入按钮
     *
     * @return Modal
     */
    public function render()
    {
        return Modal::make()
            ->lg()
            ->title(trans('admin.import'))
            ->body($this->importForm())
            ->button('<button class="btn btn-outline-primary "><i class="feather icon-file-plus"></i><span>&nbsp;&nbsp;导入</span></button>');
    }

    /**
     * 表单
     *
     * @return string
     */
    public function importForm()
    {
        $form = new Form();

        $form->disableResetButton();
        $form->disableSubmitButton();

        $form->action(admin_url('questions/import'));

        $form->file('file', 'Excel 文件')
            ->on('uploadSuccess', 'function (file, response) {
                if (response.status) {
                    Dcat.success(response.data.message);
                    Dcat.reload();
                }
            }');

        return $form->render();
    }
}
